<#include "../header.html">
<script type="text/javascript">
(function(window){
	var ext = "jpg,png,jpeg,gif,mp4";
	var size = ${imgSize!};
	var upload={
		initUpload:function(){
			$("#imgFile").change(Upload.checkUpload);
		},
		checkUpload:function(){
			var imgFile = $("#imgFile").val();
			if(imgFile==null || JFT.isBlank(imgFile)){
				alert("请选择上传图片文件");
				return;
			}
			if(!JFT.checkFile(imgFile, ext)){
				alert("上传文件格式必须是["+ext+"]");
				return;
			}
			var fileSize = JFT.getFileSize("imgFile");
			if(fileSize!=-1 && fileSize>size){
				alert("上传图片文件最大不能超过"+(size/1024)+"K");
				return;
			}
			$("#uploadBtn", parent.document).html("文件上传中");
			$("#uploadBtn", parent.document).attr("disabled",true);
			document.uploadForm.submit();
		},
		handleUpload:function(code, imgId, imgSrc){
			$("#uploadBtn", parent.document).attr("disabled",false);
			$("#uploadBtn", parent.document).html("上传文件");
			if(code == 0) {
				$("#imgId", parent.document).val(imgId);
				$("#mediaUrl", parent.document).val(imgSrc);
				return;
			}else if(code == 1){
				alert("上传失败");
				return;
			}else if(code == 2){
				alert("超过上传大小限制");
				return;
			} else if(code == 3) {
				alert("不支持的扩展名");
				return;
			}
		}
	};
	window.Upload = upload;
})(window);
$(function(){
<#if resultCode?string != "-1">	
Upload.handleUpload("${resultCode!}", "${imgId!}", "${imgSrc!}");
</#if>	
	Upload.initUpload();
});
</script>
<form id="uploadForm" name="uploadForm" method="post" action="newsAction.do?method=upload" enctype="multipart/form-data">
	<input type="hidden" id="imgType" name="imgType" value="2"/>
	<input type="hidden" id="imgId" name="imgId" value="${imgId!}"/>
	<input type="hidden" id="imgSrc" name="imgSrc" value="${imgSrc!}"/>
	<input type="file" id="imgFile" name="imgFile"/>
</form>

<#include "../footer.html">